#!/bin/bash

# 捕获SIGTERM信号并退出
trap "exit" SIGTERM

category="RAM"
log='/tmp/stress-ram.log'
err='/tmp/stress-ram.err'
cycle=${1:-'600'}

start_time=$(date +%s)

## default use ram size
ramSize='90%'

resultcode=0
resultmsg=""


echo "cycle=$cycle,ram=$ramSize" >$log
stress-ng --vm 4 --vm-bytes $ramSize --vm-method all --verify  -t $cycle -v --log-file $log 2> $err &
stress_pid=$!  # 获取 stress-ng 的进程ID

# 等待直到 stress-ng 结束或接收到SIGTERM信号
wait $stress_pid

if [ $? -ne 0 ];then
	resultcode="1"
	resultmsg=`cat $err`
fi

end_time=$(date +%s)

run_time=$((end_time - start_time))

echo "category=${category};resultcode=${resultcode};resultmsg=${resultmsg};runtime=${run_time}"
